package produce.topic;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : xiaohong
 * @date : 2021/4/11 16:32
 */

@RestController
@RequestMapping("/topic")
public class TopicController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping
    public String send(@RequestParam String msg,@RequestParam String key){
        // 交换机名称  路由key/queue队列名称  消息内容
        // fanout模式路由key必须为""
        rabbitTemplate.convertAndSend("topic_exchange",key,msg);
        return "发送给"+key+"消息成功:  "+msg;
    }

}
